import React, { useEffect, useState } from "react";
import { findFileUrlByUuid } from '@/services/base'
import { Image } from 'antd';

interface Props {
  uuid?: string,
  src?: string,
  defaultImg?: string
  [key: string]: any
}
export default function Avatar(props: Props) {
  const {
    uuid,
    src,
    defaultImg
  } = props
  const [imgUrl, setimgUrl] = useState('')
  const getImageUrl = async (fileUuid) => {
    let result = await findFileUrlByUuid({ fileUuid: fileUuid, th: 1 })
    setimgUrl(result)
  }
  useEffect(() => {
    if (src) {
      setimgUrl(src)
    } else {
      getImageUrl(uuid)
    }

  }, [uuid, src])
  return (
    <div {...props}>
      <Image src={imgUrl || defaultImg} />
    </div>

  )
}